<%@tag import="be.webchess.www.model.ChessPiece"%>
<jsp:directive.tag language="java" pageEncoding="ISO-8859-1" body-content="empty" />
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%@ attribute name="id" description="Provide id of the chessboard and prefix of sub div" required="true" type="java.lang.String" %>
<%@ attribute name="width" description="Provide the width of the board" required="true" type="java.lang.Integer" %>
<%@ attribute name="height" description="Provide the height of the board" required="true" type="java.lang.Integer" %>
<%@ attribute name="position" description="Position of pieces" required="true" type="java.util.Map" rtexprvalue="true" %>
<%@ attribute name="current_player_color" description="Color of the current player" required="true" type="java.lang.String" rtexprvalue="true" %>


<c:set var="chessgameid" value="${id}" scope="request" />


<style>

	<c:set var="num1" value="1" scope="page" />
	<c:set var="rl1" value="7" scope="page"/>
	<c:forEach var="l1" begin="0" end="7" step="1">
		<%char tmp_char1 = 'a'; %>
		<c:forEach var="c1" begin="0" end="7" step="1">
			<c:set var="letter1"	value="<%=tmp_char1 %>" />
			<c:set var="tmp_square1" value="${ letter1 }${rl1+1}"/>
			.cb_square_${tmp_square1} {
				background-image: url("${root_path}/img/chessboard_square_${tmp_square1}.png");
			}
			<c:set var="num1" value="${num1 + 1}" scope="page" />
			<%tmp_char1++; %>			
		</c:forEach>
		<c:set var="num1" value="${num1 + 1}" scope="page" />
	  	<c:set var="rl1" value="${rl1-1}" scope="page" />
	</c:forEach>


</style>

<c:set var="num" value="1" scope="page" />

<center>
<div id="ajax_err">
</div>

<table cellspacing="0" cellpadding="0" id="${id}" class="chessboard" width="${width+30}px"  height="${height+30}px">

	<tr>
		<td rowspan="10" width="15px" height="${height+30}px">
			<div class="cb_left_border">
			</div>
		</td>
		<td colspan="8" height="15px">
			<div class="cb_top_border">
			</div>		
		</td>
		<td rowspan="10" width="15px" height="${height+30}px">
			<div class="cb_right_border">
			</div>		
		</td>
	</tr>
		
	<c:set var="rl" value="7" scope="page"/>
	<c:forEach var="l" begin="0" end="7" step="1">
	
		<%char tmp_char = 'a'; %>
		<tr>

		<c:forEach var="c" begin="0" end="7" step="1">
		
<%-- 			<c:if test="${ (num % 2) == 0 }"> --%>
<%-- 				<c:set var="classe" value="cb_evenSquare" /> --%>
<%-- 			</c:if> --%>
			
<%-- 			 <c:if test="${!((num % 2) == 0)}"> --%>
<%-- 				<c:set var="classe" value="cb_oddSquare" /> --%>
<%-- 			</c:if> --%>
			
			
			
			<td width="${width/8}px"  height="${height/8}px">
				<c:set var="letter"	value="<%=tmp_char %>" />
				<c:set var="tmp_square" value="${ letter }${rl+1}" scope="request"/>

				<c:set var="classe" value="cb_square_${tmp_square}" />
				<%
					if (  position.get( request.getAttribute("tmp_square") ) != null )
					{
				%>
				<%
						ChessPiece		piece = (ChessPiece)position.get(request.getAttribute("tmp_square"));
						
						if ( current_player_color.compareToIgnoreCase(piece.getColor()) == 0 )
							request.setAttribute("pclass", "cb_valid_select_piece");
						else
							request.setAttribute("pclass", "");	
				%>
				
					<div id="${id}_location_${tmp_square}" class="${classe} ${pclass}" >
						<div id="${id}_location_filter_${tmp_square}" class="cb_invalid_move_square_filter">		
							<img style="margin-left: 5px;margin-top: 5px;" width="${(width/8)-10}px"  height="${(height/8-10)}px" src="${requestScope['root_path']}/img/${position.get(tmp_square).getImageFile()}" />
						</div>					
					</div>
				<%
					}else
					{
				%>
					<div id="${id}_location_${tmp_square}" class="${classe}" >
						<div id="${id}_location_filter_${tmp_square}" class="cb_invalid_move_square_filter">
							<![CDATA[ &nbsp; ]]>
						</div>
					</div>								
				<%
					}
				%>
			</td>
						
			
			<c:set var="num" value="${num + 1}" scope="page" />
			<%tmp_char++; %>
		</c:forEach>
		  
		</tr>			
		
		<c:set var="num" value="${num + 1}" scope="page" />
	  	<c:set var="rl" value="${rl-1}" scope="page" />
	  
	</c:forEach>

	<tr>
		<td colspan="8">
			<div class="cb_bottom_border">
			</div>		
		</td>
	</tr>

</table>
</center>

<div id="tmp_ajax_container" style="">
</div>


